<?php

function GetEmailBody($tplDir = '', $tplName, $vars)
{
    $body = array(
        'text' => '',
        'html' => ''
    );

    $tplDirPath = PATH_TEMPLATES . '/emails/' . $tplDir;
    $tplHtml = $tplName . '.html.tpl';
    $tplText = $tplName . '.tpl';

    if ( file_exists($tplDirPath . $tplHtml) )
    {
        $body['html'] = Util::ParseTemplate($tplDirPath, $tplHtml, $vars);
    }

    if ( file_exists($tplDirPath . $tplText) )
    {
        $body['text'] = Util::ParseTemplate($tplDirPath, $tplText, $vars);
    }

    return $body;
}

function GetEmailSubject($tplDir = '', $vars)
{
    $tplDirPath = PATH_TEMPLATES . '/emails/' . $tplDir;
    $tpl = 'subject.tpl';

    $subject = '';
    if ( file_exists($tplDirPath . $tpl) )
    {
        $subject = Util::ParseTemplate($tplDirPath, $tpl, $vars);
    }

    return $subject;
}

function SendFeedback($name, $email, $message)
{
    $vars = array
    (
        'NAME'          => $name,
        'EMAIL'         => $email,
        'MESSAGE'       => $message
    );

    $body    = GetEmailBody('feedback/', 'body', $vars);
    $subject = GetEmailSubject('feedback/', $vars);

    $msg = new MailMessage();
    $msg->from      = $email;
    $msg->fromName  = $name;
    $msg->to        = SUPPORT_COM_BOX;
    $msg->toName    = "CodeDrive Support";
    $msg->subject   = "Feedback";
    $msg->text      = $body['text'];
    $msg->htmlBody  = $body['html'];
    iSpringServices::SendMail( $msg );
}
   ?>
